package com.ylsk.check.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ylsk.check.domain.dto.JeevesReportDTO;
import com.ylsk.check.domain.so.JeevesReportSO;
import com.ylsk.check.domain.vo.JeevesReportVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ylsk.common.annotation.Log;
import com.ylsk.common.core.controller.BaseController;
import com.ylsk.common.core.domain.AjaxResult;
import com.ylsk.common.enums.BusinessType;
import com.ylsk.check.service.IJeevesReportService;
import com.ylsk.common.utils.poi.ExcelUtil;
import com.ylsk.common.core.page.TableDataInfo;

/**
 * 占道上报Controller
 *
 * @author yangsy
 * @date 2024-01-02
 */
@RestController
@RequestMapping("/check/jeevesReport")
public class JeevesReportController extends BaseController
{
    @Autowired
    private IJeevesReportService jeevesReportService;

    /**
     * 查询占道上报列表
     */
    @PreAuthorize("@ss.hasPermi('check:jeevesReport:list')")
    @GetMapping("/list")
    public TableDataInfo list(JeevesReportSO jeevesReportSO)
    {
        startPage();
        List<JeevesReportVO> list = jeevesReportService.selectJeevesReportList(jeevesReportSO);
        return getDataTable(list);
    }

    /**
     * 导出占道上报列表
     */
    @PreAuthorize("@ss.hasPermi('check:jeevesReport:export')")
    @Log(title = "占道上报", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JeevesReportSO jeevesReportSO)
    {
        List<JeevesReportVO> list = jeevesReportService.selectJeevesReportList(jeevesReportSO);
        ExcelUtil<JeevesReportVO> util = new ExcelUtil<JeevesReportVO>(JeevesReportVO.class);
        util.exportExcel(response, list, "占道上报数据");
    }

    /**
     * 获取占道上报详细信息
     */
    @PreAuthorize("@ss.hasPermi('check:jeevesReport:query')")
    @GetMapping(value = "/{jeevesReportId}")
    public AjaxResult getInfo(@PathVariable("jeevesReportId") Long jeevesReportId)
    {
        return success(jeevesReportService.selectJeevesReportByJeevesReportId(jeevesReportId));
    }

    /**
     * 新增占道上报
     */
    @PreAuthorize("@ss.hasPermi('check:jeevesReport:add')")
    @Log(title = "占道上报", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JeevesReportDTO jeevesReportDTO)
    {
        return toAjax(jeevesReportService.insertJeevesReport(jeevesReportDTO));
    }

    /**
     * 修改占道上报
     */
    @PreAuthorize("@ss.hasPermi('check:jeevesReport:edit')")
    @Log(title = "占道上报", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JeevesReportDTO jeevesReportDTO)
    {
        return toAjax(jeevesReportService.updateJeevesReport(jeevesReportDTO));
    }

    /**
     * 删除占道上报
     */
    @PreAuthorize("@ss.hasPermi('check:jeevesReport:remove')")
    @Log(title = "占道上报", businessType = BusinessType.DELETE)
	@DeleteMapping("/{jeevesReportIds}")
    public AjaxResult remove(@PathVariable Long[] jeevesReportIds)
    {
        return toAjax(jeevesReportService.deleteJeevesReportByJeevesReportIds(jeevesReportIds));
    }

    /**
     * 查询占道报备未撤场的数据
     */
    @GetMapping("/selectNotWithdrawnList")
    public AjaxResult selectList(JeevesReportSO jeevesReportSO)
    {
        List<JeevesReportVO> list = jeevesReportService.selectJeevesNotWithdrawnList(jeevesReportSO);
        return success(list);
    }

    @Log(title = "撤场上报", businessType = BusinessType.INSERT)
    @GetMapping("/addWithdrawalReport/{jeevesReportId}")
    public AjaxResult AddWithdrawalReport(@PathVariable("jeevesReportId") Long jeevesReportId)
    {
        return toAjax(jeevesReportService.addWithdrawalReport(jeevesReportId));

    }
}
